#ifndef PM_MANAGER_H_INCLUDED
#define PM_MANAGER_H_INCLUDED

#include "singleton.h"
#include "pm/dbobject.h"
#include "pm/criteria.h"
#include <list>
#include <wx/log.h>

namespace pm {

/**
 * \class Manager
 */
class Manager
{
	friend class Singleton<Manager>;
	
	wxSQLite3Database m_db;
	wxString          m_dbName;

protected:
	Manager();
	~Manager();
	
public:
	bool is_db_open();

	bool load(const wxString& dbname);

	bool insert(db::Object& obj);

	template<typename O>
	bool get_by_id(db::ID id, O& obj);

	template <typename O>
	void select_all(std::list<O>& objs);

	bool query(ICriteria& criteria);
	
	bool update(db::Object& obj);
	
	template <typename O>
	bool remove(db::ID id);

protected:
	void init_db();
};

typedef Singleton<Manager> ManagerST;

//{ Shotcuts
bool load(const wxString& dbname);

bool insert(db::Object& obj);

template<typename O>
bool get_by_id(db::ID id, O& obj);

template <class O>
void select_all(std::list<O>& objs);

bool select(ICriteria& criteria);

bool query(ICriteria& criteria);

bool update(db::Object& obj);

template <typename O>
bool remove(db::ID id);
//}

} // namespace pm

// include template implementation
#include "pm/manager.tpp"

#endif // PM_MANAGER_H_INCLUDED
